**************************************************************************************************************************************************************** 
* Author: Cecilia Hyunjung Mo
* Date: June 5, 2018
* Replication File for APSR - "When Do the Advantaged See the Disadvantages of Others? \\ A Quasi-Experimental Study of National Service"
**************************************************************************************************************************************************************** 



******************************************************************************** OPEN DATASET AND SET PATHWAY
**** Given the proprietary nature of the TFA Admissions Data, the admissions data needed to replicate the study requires 
**** that researchers seeking to replicate the study sign a Non-Disclosure Agreement with TFA.
**** Please fill out and sign "TFA Confidentiality Agreement_MoConn.docx" and send to research@teachforamerica.org to 
**** gain access to TFA_FinalAdmissions.dta


use TFA_FinalAdmissions.dta, replace
merge 1:1 personid using TFA_FinalSurvey.dta


******************************************************************************** MAIN TEXT


*************************** FIGURE 1 AND TABLE E.6
set more off
local dem="age4 female3 white2 gpa2 schoolselective parentalcollege2 pell class1-class5 religiosity"
mat results = J(13,3,0)
local a=1
foreach var of varlist `dem' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & started==1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = `a'
	local ++a
	}
esttab using output_demographics.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(demographics) replace 
eststo clear
* Created column to group output variables, and saved as - demographics.csv
* See R_Figure1 to see code to create Figure 1 based upon the RDD output


*************************** TABLE 1 AND FIGURE 2 AND TABLE E.7
* Reverse Code Outcome Measures for Ease of Interpretation
gen edaw1v2_2 = -(edaw1v2-1)
gen resent1_2v2_2 = -(resent1_2v2-1)
gen resent4_2v2_2 = -(resent4_2v2-1)
gen tol10_race2_2 = -(tol10_race2-1)

set more off
local combined2 = "civic33_v2 civic34_v2 systemsupport civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2 wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent1_2v2_2 resent2v2 resent3v2 resent4_2v2_2 tol10_race2_2 resent_index tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(26,3,0)
local a=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = `a'
	local ++a
	}
esttab using output_table1.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(main_categorized) replace 
eststo clear
* Created column to group output variables, and saved as - main_categorized.csv
* See R_Figure2 to see code to create Figure 2 based upon the RDD output


*************************** FIGURE 3 
set more off
local a=1
local b=1
mat results = J(4,4,0)
eststo: rd tol18_8v2 matriculated4 zscore if appyear < 2014 & ((student_africanamerican>.5 & student_africanamerican!=. & matriculated4 == 1) | matriculated4 == 0), z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
eststo: rd tol18_8v2 matriculated4 zscore if appyear < 2014 & ((student_africanamerican<=.5 & student_africanamerican!=. & matriculated4 == 1) | matriculated4 == 0), z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
eststo: rd tol18_14v2 matriculated4 zscore if appyear < 2014 & ((student_latino>.5 & student_latino!=. & matriculated4 == 1) | matriculated4 == 0), z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
eststo: rd tol18_14v2 matriculated4 zscore if appyear < 2014 & ((student_latino<=.5 & student_latino!=. & matriculated4 == 1) | matriculated4 == 0), z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
esttab using output_racedose.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(racedosage) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - racedosage.csv
* See R_Figure2 to see code to create Figure 3 based upon the RDD output


*************************** OTHER NUMBERS IN THE TEXT 
*** Response Rates
su finished started if appyear < 2014
su finished started if appyear < 2014 & matriculated4 == 1
su finished started if appyear < 2014 & matriculated4 == 0
su finished started if appyear >= 2014 & appyear !=. 
* Use these numbers to compute response rates for main text

*** Cronbach Alpha Scores for Indices
alpha civic33_v2 civic34_v2 
alpha civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2
alpha resent1_2v2 resent2v2 resent3v2 resent4_2v2 tol10_race2 
alpha tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 

*** Footnote 18
rd dem15_IN matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)

*** Continuity of Score at Cutoff
by zscore, sort: egen count3 = count(0) if appyear<2014
rd count3 matriculated4 zscore if appyear < 2014, z0(0) cluster(zscore) kernel(triangular)

*** Footnote 27
rd zip_frac matriculated4 zscore if appyear < 2011, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)

*** Admission Component Score: "Respect for Individuals' Diverse Experiences..."
rd brids matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)

*** Party ID Difference at Cutoff
rd pid_reptodem matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)

*** Footnotes 39-40, and Gender Discussion
su pell if appyear < 2014 & started==1 & zscore !=.
su pell if appyear < 2014 & zscore !=.

su white2 if appyear < 2014 & started==1 & zscore !=.
su white2 if appyear < 2014 & zscore !=.

su female3 if appyear < 2014 & started==1 & zscore !=.
su female3 if appyear < 2014 


******************************************************************************** APPENDIX

*************************** APPENDIX A
*** TABLE A.1, PANEL A: FIRST STAGE RESULTS
* Restrict to those who started the survey, and include cohort controls given they are included for main analyses
set more off
local fs="admit matriculated4"
foreach var of varlist `fs' {
	label variable `var' "`var'"
	eststo: rd `var' zscore if appyear < 2014 & started == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	}
esttab using output_firststage_rd.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(lwald lwald50 lwald200) coeflabels(lwald "2SLS" lwald50 "2SLS (0.5 Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
eststo clear

*** TABLE A.1, PANEL B: RESPONSE RATE RESULTS 
set more off
local rr="complete started"
foreach var of varlist `rr' {
	label variable `var' "`var'"
	eststo: rd `var' zscore if appyear < 2014, z0(0) cov() cluster(zscore) kernel(triangular)
	}
esttab using output_responserate_rd.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(lwald lwald50 lwald200) coeflabels(lwald "2SLS" lwald50 "2SLS (0.5 Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
eststo clear

*** FIGURE A.1: RESPONSE RATE
tab appyear finished, mi row
tab appyear started, mi row
* Use these numbers to create overall_responserate.csv to input into R
* See R_FigureA1 to see code to create Figure A.1

*** FIGURES A.2 AND A.3
* See R_FigureA2A3D to see code to create Figures A.2 and A.3


*************************** APPENDIX B
*** TABLE B.2: SUMMARY STATISTICS OF DEMOGRAPHIC CHARACTERISTICS
* Restrict to survey participants (as have demographic characteristics from application file, which includes those who did not participate
su age female3 white2 gpa2 schoolselective parentalcollege2 pell class1-class5 religiosity if appyear < 2014 & started==1 & zscore !=.
*** Representativeness
global dem="age3 female3 white2 gpa2 schoolselective pell"
su $dem zscore appyear if appyear <2014 & admit == 0
su $dem zscore appyear if appyear <2014 & admit == 0 & started == 1
su $dem zscore appyear if appyear <2014 & matriculated4 == 1
su $dem zscore appyear if appyear <2014 & matriculated4 == 1 & started == 1

*** TABLE B.3: SUMMARY STATISTICS OF OUTCOME MEASURES
su civic33_v2 civic34_v2 systemsupport civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2 wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent1_2v2_2 resent2v2 resent3v2 resent4_2v2_2 tol10_race2_2 resent_index tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 discrim_index3 iatscore_2 tol18_8v2 tol18_14v2 tol18_5v2 tol18_6v2 if appyear < 2014 & zscore !=.

*** TABLE B.4: SUMMARY STATISTICS OF OUTCOME MEASURES BY MATRICULATION AND ADMISSION STATUS
set more off
gen group = 0 if admit == 0
recode group (.= 1) if admit == 1 & matriculated4 == 0
recode group (.= 2) if admit == 1 & matriculated4 == 1

global outcome = "civic33_v2 civic34_v2 systemsupport civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2 wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent1_2v2_2 resent2v2 resent3v2 resent4_2v2_2 tol10_race2_2 resent_index tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
orth_out $outcome if appyear < 2014 using Tableb4.csv, by(group) compare replace


*************************** APPENDIX D
*** FIGURES D.5-D.7
* See R_FigureA2A3D to see code to create Figures D.4, D.5, D.6, and D.7


*************************** APPENDIX E
*** TABLES E.6 & E.7
* See commands for Figure 1 and Table 1 above. RDD output visualized in Figures E.6 and E.7, respectively.

*** TABLE E.8: ITT vs. TOT
set more off
local combined2 = "civic33_v2 civic34_v2 systemsupport civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2 wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent1_2v2_2 resent2v2 resent3v2 resent4_2v2_2 tol10_race2_2 resent_index tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(26,3,0)
local a=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' admit zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	}
esttab using Tablee8.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
eststo clear

*** TABLE E.9: BENCHMARKING
* Follow TableE9_Benchmarking.do to compute values for columns (1)-(3)
* Values used for columns (4)-(7) drawn from code in Table E.8

* Indices for WVS and Racial Resentment needed to be revised to match existing data in outside surveys
* ITT and TOT for Revised Class-Based Resentment Index (Row 7)
gen wvs_libindex_modified = (civic31b_wv2+civic31c_wv2+civic31d_wv2)/3
rd wvs_libindex_modified matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
rd wvs_libindex_modified admit zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)

* ITT and TOT for Revised Racial Resentment Index (Row 12)
gen resent_index_modified = (resent1_2v2 + resent2v2 + resent3v2 + resent4_2v2)/4
rd resent_index_modified matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
rd resent_index_modified admit zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
* TableE9_Benchmarking.xlsx computes columns (3), (6), and (7) based upon the output.

*** FIGURE E.8
* Pooling 2007/2008, as first stage in 2008 is not robust
set more off
eststo: quietly rd resent_index matriculated4 zscore if appyear < 2009, z0(0) cov(app_year1-app_year2) cluster(zscore) kernel(triangular)
		forvalues i = 2009(1)2013  {
		eststo: quietly rd resent_index matriculated4 zscore if appyear == `i', z0(0) cluster(zscore) kernel(triangular)
		}
eststo: quietly rd iatscore_2 matriculated4 zscore if appyear < 2009, z0(0) cov(app_year1-app_year2) cluster(zscore) kernel(triangular)
		forvalues i = 2009(1)2013  {
		eststo: quietly rd iatscore_2 matriculated4 zscore if appyear == `i', z0(0) cluster(zscore) kernel(triangular)
		}
esttab using output_durability.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
eststo clear
* Extracted 2SLS estimates - durability.csv
* 2X bandwidth estimates are visualized for the IAT figure given missing data issues for this measure (see main text for added discussion)
* See R_FigureE8 to see code to create Figure E.8

*** FIGURE E.9: PLACEBO (ELDERLY/CHRISTIANS)
set more off
local a=1
mat results = J(2,3,0)
eststo: rd tol18_5v2 matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	local ++a
eststo: rd tol18_6v2 matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	local ++a
esttab using figuree9_elderlychristian.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(elderly) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - elderly.csv
* See R_FigureE9 to see code to create Figure E.9

*** FIGURE E.10: OUTCOME ASSOCIATED WITH MATRICULATION
set more off
global outcome = "civic33_v2 civic34_v2 systemsupport civic31b_wv2 civic31c_wv2 civic31d_wv2 civic31e_wv2 wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent1_2v2_2 resent2v2 resent3v2 resent4_2v2_2 tol10_race2_2 resent_index tol_us2_1v2 tol_us2_3v2 tol_us2_4v2 tol_us2_5v2 tol_us2_6v2 discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
global dem="age female3 white2 gpa2 schoolselective parentalcollege2 pell class1-class5 religiosity"
mat results = J(26,3,0)
local a=1
foreach var of varlist $outcome {
	label variable `var' "`var'"
	eststo: reg `var' matriculated4 zscore $dem app_year1-app_year9 if appyear < 2014 & admit == 1
	mat results[`a',1] = _b[matriculated4]
	mat results[`a',2] = _se[matriculated4]
	mat results[`a',3] = `a'
	local ++a
	}
esttab using output_matriculant_main.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label replace
mat2txt, matrix(results) saving(main_matric) replace
eststo clear
* Converted txt file to csv file to input into R, and saved as - matriculation.csv
* See R_FigureE10 to see code to create Figure E.10

*** FIGURE E.11: TIME DOSAGE
set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if date_restriction3==1, z0(0) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_dosage.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(dosage) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - dosage.csv
* See R_FigureE11 to see code to create Figure E.11

*** FIGURE E.12: AGE
* birth year: pre3_0
* application year: appyear
gen yr=year(dob)
gen pre3_update = 1949+ pre3_0
replace pre3_update = yr if pre3_update == .
gen ageatapp_year2 = appyear-pre3_update
gen youth3 = 1 if ageatapp_year2 < 25
replace youth3 = 0 if ageatapp_year2 >=25 & ageatapp_year2 !=.
gen odd2 = 1 if ageatapp_year2 < 18 

set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & youth3 == 1 & odd2 != 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & youth3 == 0 & odd2 != 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_age.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(age) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - age.csv
* See R_FigureE12 to see code to create Figure E.12

*** FIGURE E.13: PELL
set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & pell== 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & pell==0, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_pell.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(pell) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - pell.csv
* See R_FigureE13 to see code to create Figure E.13

*** FIGURE E.14: RACE
set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & white == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & white == 0, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_white.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(white) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - white=.csv
* See R_FigureE14 to see code to create Figure E.14

*** FIGURE E.15: PARTY ID
set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(30,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & pid_reptodem < 0.5, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & pid_reptodem==0.5, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & pid_reptodem > 0.5, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 3
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_pid2.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(pid2) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - pid2.csv
* See R_FigureE15 to see code to create Figure E.15

*** FIGURE E.16: GENDER
set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & female3 == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & female3 == 0, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_gender.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(gender) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - gender.csv
* See R_FigureE16 to see code to create Figure E.16

*** FIGURE E.17: EDUCATION/LEGAL/NON-PROFIT
* CAREER NON-ADMIT
gen ednonlegal = 1 if career9a1n_2_1 == 9 | career9a1n_2_1 ==15 | career9a1n_2_1 == 16 | career9a1n_2_1 == 17 | career9a1n_2_1 == 18 | career9a1n_2_1 == 33 | career9a1n_2_1 == 35 | career9a1n_2_1 == 42 | career9a1n_2_1 == 43 | career9a1n_2_1 == 46 | career9a1n_2_1 == 56
gen ednonlegal2 = 1 if career9a1n_2_2 == 9 | career9a1n_2_2 ==15 | career9a1n_2_2 == 16 | career9a1n_2_2 == 17 | career9a1n_2_2 == 18 | career9a1n_2_2 == 33 | career9a1n_2_2 == 35 | career9a1n_2_2 == 42 | career9a1n_2_2 == 43 | career9a1n_2_2 == 46 | career9a1n_2_2 == 56
gen ednonlegal3 = 1 if career9a1n_2_3 == 9 | career9a1n_2_3 ==15 | career9a1n_2_3 == 16 | career9a1n_2_3 == 17 | career9a1n_2_3 == 18 | career9a1n_2_3 == 33 | career9a1n_2_3 == 35 | career9a1n_2_3 == 42 | career9a1n_2_3 == 43 | career9a1n_2_3 == 46 | career9a1n_2_3 == 56
gen ednonlegal_sample = 1 if ednonlegal == 1 | ednonlegal2 == 1 | ednonlegal3 == 1 | matriculated4 == 1

set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & ednonlegal_sample == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_ednonlegal_sample.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(ednonlegal_sample) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - ednonlegal.csv
* See R_FigureE17 to see code to create Figure E.17

****** FIGURE E.18: RELIGIOUS AFFILIATION
gen unaffiliated = 1 if dem11 == 10 | dem11 == 8 | dem11 == 9
recode unaffiliated (.=0) if dem11 !=.

set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & unaffiliated == 0, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & unaffiliated == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_rel.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(religion) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - religion.csv
* See R_FigureE18 to see code to create Figure E.18

********** FIGURE E.19: GRADE LEVEL
gen elem = 1 if pre_teach_1 == 1 | pre_teach_3 == 1 | pre_teach_4 == 1 | pre_teach_5 == 1 | pre_teach_6 == 1 | pre_teach_7 == 1 | pre_teach_8 == 1 
gen secondary = 1 if  pre_teach_9 == 1 | pre_teach_10 == 1 | pre_teach_11 == 1 | pre_teach_12 == 1 | pre_teach_13 == 1 | pre_teach_14 == 1 | pre_teach_15 == 1

gen gradesample = 1 if matriculated4 == 0
replace gradesample = 1 if matriculated4 == 1 & elem == 1 

gen gradesample2 = 1 if matriculated4 == 0
replace gradesample2 = 1 if matriculated4 == 1 & secondary == 1 

set more off
local combined2 = "systemsupport wvs_libindex edpol1a_su2_v2 edpol1a_su6_v2 edaw1v2_2 resent_index discrim_index3 iatscore_2 tol18_8v2 tol18_14v2"
mat results = J(20,4,0)
local a=1
local b=1
foreach var of varlist `combined2' {
	label variable `var' "`var'"
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & gradesample == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 1
	mat results[`a',4] = `b'
	local ++a
	eststo: quietly rd `var' matriculated4 zscore if appyear < 2014 & gradesample2 == 1, z0(0) cov(app_year1-app_year9) cluster(zscore) kernel(triangular)
	mat results[`a',1] = _b[lwald]
	mat results[`a',2] = _se[lwald]
	mat results[`a',3] = 2
	mat results[`a',4] = `b'
	local ++a
	local ++b
	}
esttab using output_elem.csv, b(3) se(3) starlevels(* 0.1 ** .05 *** .01) label order(denom numer lwald denom50 numer50 lwald50 denom200 numer200 lwald200) coeflabels(numer "Reduced Form" denom "First Stage" lwald "2SLS" numer50 "Reduced Form (0.5 Optimal Bandwidth)" denom50 "First Stage (0.5 Optimal Bandwidth)" lwald50 "2SLS (0.5 Optimal Bandwidth)" numer200 "Reduced Form (2X Optimal Bandwidth)" denom200 "First Stage (2X Optimal Bandwidth)" lwald200 "2SLS (2X Optimal Bandwidth)") replace
mat2txt, matrix(results) saving(elem) replace 
eststo clear
* Converted txt file to csv file to input into R, and saved as - elem.csv
* See R_FigureE19 to see code to create Figure E.19


*************************** APPENDIX H
** CAREER NON-ADMIT
tab career9a1n_2_1 if appyear<2014 & zscore !=. & matriculated4 != 1
tab career9a1n_2_2 if appyear<2014 & zscore !=. & matriculated4 != 1
tab career9a1n_2_3 if appyear<2014 & zscore !=. & matriculated4 != 1
* Output imported into AppendixH_Careers.xlsx to generate the three figures.

